import {request} from "@/network/request";

//获取全部分类信息
export function allCategories() {
  return request({
    url: '/categories/allCategories',
    method: 'get'
  })
}

//获取全部标签信息
export function allTags() {
  return request({
    url: '/tags/allTags',
    method: 'get'
  })
}

export function insertArticle(title, contentHtml, contentMd,
                              categoryId, tagsId, description,allowComment) {
  return request({
    url: '/article/insertArticle',
    method: 'post',
    data: {
      title,
      contentHtml,
      contentMd,
      categoryId,
      tagsId,
      description,
      allowComment
    }
  })
}

export function updateArticle(articleId, title, contentHtml, contentMd,
                              description,allowComment) {
  return request({
    url: '/article/updateArticle',
    method: 'post',
    data: {
      articleId,
      title,
      contentHtml,
      contentMd,
      description,
      allowComment
    }
  })
}

export function insertImage(formdata) {
  return request({
    url: '/article/insertImage',
    headers: {'Content-Type': 'multipart/form-data'},
    method: 'post',
    data: formdata,
  })
}

//插入数据到草稿箱
export function insertDraft(articleId, title, contentHtml, contentMd) {
  return request({
    url: '/draft/insertDraft',
    method: 'post',
    data: {
      articleId,
      title,
      contentHtml,
      contentMd
    }
  })
}

//存在草稿箱Id则进行更新数据操作
export function updateDraft(id, articleId, title, contentHtml, contentMd) {
  return request({
    url: '/draft/updateDraft',
    method: 'post',
    data: {
      id,
      articleId,
      title,
      contentHtml,
      contentMd
    }
  })
}

//判断该文章是否存在草稿
export function judgeDraft(articleId) {
  return request({
    url: '/draft/judgeDraft',
    params: {
      articleId
    }
  })
}